package com.carsystem.controller;


import com.carsystem.entity.OpenRendVo;
import com.carsystem.entity.Openrend;
import com.carsystem.request.OpenRendRequestVo;
import com.carsystem.response.OpenRendResponseVo;
import com.carsystem.service.IOpenrendService;
import com.carsystem.utils.*;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ykl
 * @since 2021-12-04
 */
@RestController
@RequestMapping("/openrend")
public class OpenrendController extends BaseController{
    @Reference
    private IOpenrendService openrendService;

    /**
     * 发布租车分页查询
     * @param openRendRequestVo
     * @return
     */
    @RequestMapping("/selectPage")
    public ResultEntity<OpenRendResponseVo> selectOrderByPage(@RequestBody OpenRendRequestVo openRendRequestVo){
        HashMap<Object, Object> map = new HashMap<>();
        PageHandler pageHandler = openrendService.selectOpenRendByPage(openRendRequestVo);
        map.put("page",pageHandler);
        return getSuccessEntity(map);

    }


    /**
     * 新增发布
     * @param openrend
     * @param carbrandIds
     * @param carIds
     * @param shopIds
     * @return
     */
    @RequestMapping("/addOpenRend")
    public Result addOpenRend(@RequestBody Openrend openrend,int[] carbrandIds,int[] carIds,int[] shopIds){
        return openrendService.addOpenrend(openrend,carbrandIds,carIds,shopIds);
    }

    /**
     *  根据id查找到店铺、汽车品牌、汽车信息 数据
     * @param id
     * @return
     */
    @RequestMapping("/getOpenRendById/{id}")
    public Result getOpenRendById(@PathVariable int id){
        OpenRendVo openRendById = openrendService.getOpenRendById(id);
        return new Result(true,"查询成功",openRendById);
    }

    /**
     * 更新发布
     * @param openrend
     * @param carbrandIds
     * @param carIds
     * @param shopIds
     * @return
     */
    @RequestMapping("/updateOpenRend")
    public Result updateOpenRend(@RequestBody Openrend openrend,int[] carbrandIds,int[] carIds,int[] shopIds){
        return openrendService.updateOpenrend(openrend,carbrandIds,carIds,shopIds);
    }

    /**
     * 删除发布
     * @param id
     * @return
     */
    @RequestMapping("/deleteOpenrend/{id}")
    public Result deleteOpenrend(@PathVariable int id){
        return openrendService.deleteOpenrend(id);
    }

}

